import cv2 as cv
import numpy as np


def trackbar_callback1(value):
    pass


def trackbar_callback2(value):
    pass


def canny_detect_func():
    win_name = 'destination image'
    trackbar_1 = 'threshold 1'
    trackbar_2 = 'threshold_2'
    src_img = cv.imread('..//lena.png')
    cv.imshow('source image', src_img)
    cv.namedWindow(win_name, cv.WINDOW_AUTOSIZE)
    cv.createTrackbar(trackbar_1, win_name, 100, 300, trackbar_callback1)
    cv.createTrackbar(trackbar_2, win_name, 200, 300, trackbar_callback2)

    while 1:
        val1 = cv.getTrackbarPos(trackbar_1, win_name)
        val2 = cv.getTrackbarPos(trackbar_2, win_name)
#       print("val1 = ", val1, "val2 = ", val2)
        dst_img = cv.Canny(src_img, val1, val2)
        cv.imshow(win_name, dst_img)
        key = cv.waitKey(5)
        if key == 27:
            break
    cv.destroyAllWindows()


if __name__ == '__main__':
    canny_detect_func()
